/**
 * 船模 编辑页
 *
 * 作者 ganjun
 * 日期 2024-11-13 19:03:49
 */
layui.use(['jquery','febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#modelShip-edit'),
        laydate = layui.laydate,

        $sourceSelect = $view.find('#sourceSelect'),
        $shipPositionSelect = $view.find('#shipPositionSelect'),
        $shipTypeSelect = $view.find('#shipTypeSelect'),
        $modelTypeSelect = $view.find('#modelTypeSelect'),

        validate = layui.validate;

    // initDictItemSelect();

    form.verify(validate);
    form.render();
    initFormValue();


    function initDictItemSelect() {
        if(modelShipData){
            //船模来源
            febs.initDictItemSelect($sourceSelect, 'SHIP_MODEL_SOURCE', modelShipData.source, null);
            //船模位置
            febs.initDictItemSelect($shipPositionSelect, 'SHIP_MODEL_POSITION', modelShipData.shipPosition, null);
            //船舶类型
            febs.initDictItemSelect($shipTypeSelect, 'SHIP_TYPE', modelShipData.shipType, null);
            //船模类型
            febs.initDictItemSelect($modelTypeSelect, 'SHIP_MODEL_TYPE', modelShipData.modelType, null);
        }else{
            //船模来源
            febs.initDictItemSelect($sourceSelect, 'SHIP_MODEL_SOURCE', null);
            //船模位置
            febs.initDictItemSelect($shipPositionSelect, 'SHIP_MODEL_POSITION', null);
            //船舶类型
            febs.initDictItemSelect($shipTypeSelect, 'SHIP_TYPE', null);
            //船模类型
            febs.initDictItemSelect($modelTypeSelect, 'SHIP_MODEL_TYPE', null);
        }
    }

    function initFormValue() {
        if (modelShipData) {
            form.val("modelShip-edit-form", {
                "id": modelShipData.id,
                "shipCode": modelShipData.shipCode,
                "projectCode": modelShipData.projectCode,
                "shipName": modelShipData.shipName,
                "source": modelShipData.source,
                "status": modelShipData.status,
                "demandEnddate": modelShipData.demandEnddate,
                "actuallyStartdate": modelShipData.actuallyStartdate,
                "actuallyEnddate": modelShipData.actuallyEnddate,
                "shipType": modelShipData.shipType,
                "rate": modelShipData.rate,
                "modelType": modelShipData.modelType,
                "applyDate": modelShipData.applyDate,
                "lengthOrigal": modelShipData.lengthOrigal,
                "lengthModel": modelShipData.lengthModel,
                "columnWidthOrigal": modelShipData.columnWidthOrigal,
                "columnWidthModel": modelShipData.columnWidthModel,
                "widthOrigal": modelShipData.widthOrigal,
                "widthModel": modelShipData.widthModel,
                "waterDeepOrigal": modelShipData.waterDeepOrigal,
                "waterDeepModel": modelShipData.waterDeepModel,
                "bodyDeepOrigal": modelShipData.bodyDeepOrigal,
                "bodyDeepModel": modelShipData.bodyDeepModel,
                "axieHightOrigal": modelShipData.axieHightOrigal,
                "axieHightModel": modelShipData.axieHightModel,
                "axieWidthOrigal": modelShipData.axieWidthOrigal,
                "axieWidthModel": modelShipData.axieWidthModel,
                "rectRate": modelShipData.rectRate,
                "blockNumber": modelShipData.blockNumber,
                "weight": modelShipData.weight,
                "headHeight": modelShipData.headHeight,
                "tailHeight": modelShipData.tailHeight,
                "headPush": modelShipData.headPush,
                "tailPush": modelShipData.tailPush,
                "memo": modelShipData.memo,
                "origShipCode": modelShipData.origShipCode,
            });
        }

        // if(bmNo){
        //     form.val("modelShip-edit-form", {
        //         "shipCode": bmNo,
        //     });
        // }
        //
        // if(now){
        //     form.val("modelShip-edit-form", {
        //         "applyDate": now,
        //     });
        // }

        //编辑页面根据不同的source显示不同属性
        if(modelShipData && modelShipData.source){
            changeSource(modelShipData.source.toString());
        }
        if(modelShipData && modelShipData.modelType){
            modelTypeCtrl(modelShipData.modelType.toString());
        }

    }

    // form.on('submit(modelShip-edit-form-submit)', function (data) {
    //     addOrUpdate(data.field);
    //     return false;
    // });

    //船模来源选择控制
    // form.on('select(sourceSelect)', function (data) {
    //     var val = data.value;
    //     changeSource(val);
    // });

    //选择不通来源，显示不同属性
    function changeSource(srouceVal){
        if(srouceVal === '1'){
            $('#layui-row-source1').show();
            $('#layui-row-source2').show();
            $('#ship_major_element_fieldset').show();
            $('#ship_process_demand_fieldset').show();
            $('#origShipCodeDiv').hide();
        }else if(srouceVal === '2'){
            $('#layui-row-source1').hide();
            $('#layui-row-source2').hide();
            $('#ship_major_element_fieldset').hide();
            $('#ship_process_demand_fieldset').hide();
            $('#origShipCodeDiv').show();
        }else if(srouceVal === '3'){
            $('#layui-row-source1').hide();
            $('#layui-row-source2').hide();
            $('#ship_major_element_fieldset').hide();
            $('#ship_process_demand_fieldset').hide();
            $('#origShipCodeDiv').hide();
        }
    }

    //船模类型控制
    function modelTypeCtrl(val){
        if(val === '5'){
            $('#modelTypeOtherDiv').show();
        }else{
            $('#modelTypeOtherDiv').hide();
        }
    }

    $('#reset').click(function () {
        closeCur();
    });

    function closeCur(){
        var currentUrl = window.location.hash.replace('#', '');
        febs.view.tab.del(currentUrl);
        febs.view.tab.change("/modelShip");
        $('#febs-modelShip').find('#query').trigger('click');
    }
});